import { observable, action, computed } from 'mobx';
import { RouterStore } from 'mobx-react-router';
import AuthStore from './AuthStore';
import api from '../api/ComponentApi';
// import collapse from 'antd';

// 消息类型定义
export interface MessageType {
    id: string;
    title: string;
    content: string;
}

// 热事件类型定义
export interface HotEventType {
    title: string;
    value: Array<HotEventValueType>;
}

// 热事件值定义
export interface HotEventValueType {
    content: string;
    department: string;
    date: string;
}

export default class ComponentStore {
    // 热门事件切换按钮索引
    @observable hotEventIndex: number = 0;
    // 消息列表跳转索引
    @observable messageListIndex: number = 0;
    // home_list 列表跳转索引
    @observable graphListIndex: number = 0;
    // 当前通知
    @observable currentMessage: MessageType;
    // 通知列表
    @observable messageList: Array<MessageType>;
    // 热事件
    @observable hotEventData: Array<HotEventType>;
    // 重制密码页标题
    @observable resetTitle: string;
    // 当前激活导航栏
    @observable currentTab: string | null = null;
    // 吐司flag
    @observable isShowToast: boolean = false;
    // 失败标识
    @observable failToLogin: boolean | null;
    // 成功标示
    @observable successToLogin: boolean | null;

    @computed
    get toastFlag(): boolean {
        return this.isShowToast;
    }
    set toastFlag(flag: boolean) {
        this.isShowToast = flag;
    }
    
    @action.bound
    getMessageList(): void {
        this.messageList = api.getMessageList();
    }
    @action.bound
    getHotEventData(): void {
        this.hotEventData = api.getHotEventData();
    }

    @action.bound
    routingToPage(pageName: string, routingStore: RouterStore, authStore: AuthStore) {
        if (!authStore.isLogin) {
            return;
        }
        routingStore.push(`/${pageName}`);
    }

    @action.bound
    setResetTitle(curTitle: string) {
        this.resetTitle = curTitle;
    }

    @action.bound
    setGraphListIndex(curIndex: number) {
        this.graphListIndex = curIndex;
    }

    @action.bound
    setMessageListIndex(curIndex: number) {
        this.messageListIndex = curIndex;
    }
}